﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FrmHotel
{
    public partial class FrmTianJiaXF : Form
    {
        public FrmTianJiaXF()
        {
            InitializeComponent();
        }
        public int id;//接收主菜单的房间号
        private void FrmTianJiaXF_Load(object sender, EventArgs e)
        {
            BoinComdoBox();
            BoinDataGridView1();
          
        }
        //显示类型的方法
        public void BoinComdoBox()
        {
            string sql = "select * from CommodityClass";
            DataTable dt = DBHelper.SelectForTable(sql);
            DataRow dr = dt.NewRow();
            dr["ClassId"] = 0;
            dr["ClassName"] = "全部";
            dt.Rows.InsertAt(dr, 0);
            this.comboBox1.DisplayMember = "ClassName";
            this.comboBox1.ValueMember = "ClassId";
            this.comboBox1.DataSource = dt;
        }
        public void BoinDataGridView1()
        {
            this.dataGridView1.AutoGenerateColumns = false;
            string sql = "select c.CyName,c.CyPrice,c.CyStock from  Commodity c,CommodityClass t where t.ClassId=c.CyClass and 1=1";
            int id = Convert.ToInt32(this.comboBox1.SelectedValue);
            if (id != 0)
            {
                sql += string.Format(" and c.CyClass={0}", id);
            }
            string name = this.textBox1.Text;
            if (!string.IsNullOrEmpty(name))
            {
                sql += string.Format(" and c.CyName like '%{0}%'", name);
            }
            this.dataGridView1.DataSource = DBHelper.SelectForTable(sql);
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            BoinDataGridView1();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            BoinDataGridView1();
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            
        }
    }
}
